<template>
  <div class="file_list tab_pane" :class="{'hasSearch':hasSearch}">
    <div class="multiple_search" v-if="hasSearch">
      <div class="search_item">
        <div class="select_label">
          文档类型：
        </div>
        <div class="search_wrapper">
          <el-select
            v-model="fileType"
            multiple
            collapse-tags
            placeholder="请选择文档类型"
            size="small">
            <el-option
              v-for="(item,index) in fileTypeList"
              :key="index"
              :label="item.label"
              :value="item.id">
            </el-option>
          </el-select>
        </div>
      </div>
      <div class="search_item">
        <div class="select_label">
          文件名称：
        </div>
        <div class="search_wrapper">
          <el-input
            v-model="fileName"
            clearable
            size="small"
            placeholder="请输入文件名称">
          </el-input>
        </div>
      </div>
      <div class="mes_btn">
        <el-button
          type="primary"
          icon="el-icon-search"
          class="search_btn"
          @click="filterSearchFile">
        </el-button>
      </div>
    </div>
    <!--<span class="list_title" v-if="title">{{title}}</span>-->
    <div class="card_panel">
      <div class="empty_panel" v-if="techProcList.length===0">
        <img src="@/assets/img/pic_default_empt_search.png">
        <span>{{noFile}}</span>
      </div>
      <div class="file_item" v-for="item in fileList" v-bind:key="item.id" v-if="techProcList.length>0">
        <span class="img_file" :class="checkFileType(item.fileName)"></span>
        <span class="file_name">{{item.fileName}}</span>
        <div class="file_cell">
          <a title="查看" v-if="$checkPreviewName(item.fileName)&&$checkPreviewSize(item.fileSize)"
             @click="$previewFile(item.id, item.fileSize)"><i class="iconfont icon-chakan"></i></a>
          <span title="下载" @click="$downByBlob(item.id, item.fileName)"><i class="iconfont icon-xiazai"></i></span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'WorkStageTechFile',
  props: {
    techProcList: {
      type: Array,
      defaultProps: []
    },
    title: {
      type: String,
      defaultProps: ''
    },
    noFile: {
      type: String,
      defaultProps: ''
    },
    hasSearch: {
      type: Boolean,
      defaultProps: false
    },
    fileTypeList: {
      type: Array,
      defaultProps: []
    }
  },
  data() {
    return {
      fileName: '',
      fileType: [], // 搜索文件类型
      fileList: []
    }
  },
  mounted() {
    this.fileList = this.techProcList
  },
  methods: {
    /**
     * 判断工艺文件类型
     * @param str 文件名
     */
    checkFileType(str) {
      let fileName = str.toLowerCase()
      if (fileName.match(/.(doc|docx)$/)) {
        return 'word'
      }
      if (fileName.match(/.pdf$/)) {
        return 'pdf'
      }
      if (fileName.match(/.(xls|xlsx)$/)) {
        return 'excel'
      }
      return 'other'
    },
    /**
     * 查询文件
     */
    filterSearchFile() {
      if (this.techProcList.length) {
        if (this.fileType.length) {
          this.fileList = this.techProcList.filter((item) => {
            return item.fileName.indexOf(this.fileName) > -1 && this.fileType.indexOf(item.fileTypeId) > -1
          })
        } else {
          this.fileList = this.techProcList.filter((item) => {
            return item.fileName.indexOf(this.fileName) > -1
          })
        }
      }
    },
  },
  watch: {
    techProcList: {
      handler() {
        this.fileList = this.techProcList
      },
      deep: true
    }
  },
}
</script>

<style lang="less">
  .file_list.tab_pane{
    height: 100%;
    &.hasSearch .card_panel{
      min-height: calc(100% - 72px);
    }
  }
  .file_list {
    border: @mesBorDefault;
    color: #333;
    padding: 0 2px 0 20px;
    overflow-y: auto;
    position: relative;
    &::-webkit-scrollbar {
      /*滚动条*/
      width: 17px;
      height: 17px;
      cursor: pointer;
      margin-left: 4px;
    }
    &::-webkit-scrollbar-thumb {
      /*小方块*/
      border-radius: 16px;
      box-shadow: @mesTableScrollThumbShow;
      background: @mesTableScrollThumbBg;
      cursor: pointer;
      border: @mesTableScrollThumbBorder;
    }
    &::-webkit-scrollbar-thumb:hover {
      cursor: pointer;
    }
    &::-webkit-scrollbar-track {
      /*轨道*/
      width: 17px;
      background: @mesTableScrollTrackBg;
    }
    &::-webkit-scrollbar-track:hover {
      cursor: pointer;
    }
    .list_title {
      font-size: 18px;
      display: block;
      padding-top: 20px;
      border-right: @mesBorDefault;
    }
    .empty_panel{
      position: absolute;
      left: 50%;
      margin-left: -50px;
      margin-top: 80px;
      text-align: center;
      img{
        display: block;
        width: 100px;
        height: 100px;
        margin-bottom: 10px;
      }
      span{
        color: #a1b1c1;
      }
    }
    .card_panel {
      display: flex;
      flex-flow: row wrap;
      min-height: 100%;
      // border-right: @mesBorDefault;
      position: relative;
      .file_item {
        width: 180px;
        height: 195px;
        text-align: center;
        margin-top: 20px;
        padding-top: 20px;
        position: relative;
        cursor: pointer;
        overflow: hidden;
        margin-right: 10px;
        .img_file{
          display: block;
          width: 100px;
          height: 110px;
          margin: 0 auto;
          margin-bottom: 10px;
          background-size: cover!important;
          &.pdf{
            background: url(./../../assets/img/pic_pdf.png) no-repeat;
          }
          &.word{
            background: url(./../../assets/img/pic_word.png) no-repeat;
          }
          &.excel{
            background: url(./../../assets/img/pic_exl.png) no-repeat;
          }
          &.other{
            background: url(./../../assets/img/pic_file.png) no-repeat;
          }
        }
        img {
          display: block;
          width: 100px;
          height: 110px;
          margin: 0 auto;
          margin-bottom: 10px;
        }
        .file_name {
          font-size: 14px;
        }
        &:hover .file_cell {
          display: flex;
        }
        .file_cell {
          display: none;
          position: absolute;
          bottom: 0;
          left: 0;
          width: 100%;
          height: 0;
          z-index: 2;
          background-color: rgba(247, 247, 247, 0.8);
          justify-content: space-around;
          align-items: center;
          padding: 0 30px;
          box-sizing: border-box;
          animation: cell_card 0.4s ease forwards;
          i {
            font-size: 36px;
            &:hover {
              color: #2196f3;
            }
          }
        }
        @keyframes cell_card {
          from {
            height: 0;
          }
          to {
            height: 100%;
          }
        }
      }
    }
  }
</style>
